package com.qf.controller;
//管理员登录

import com.qf.pojo.User;
import com.qf.service.AdminService;
import com.qf.service.serviceImpi.AdminServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/admin")
public class AdminController extends BaseServlet {



    public String login(HttpServletRequest request, HttpServletResponse response) {
        //获取参数
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        //判断用户名、密码是否为空
        if (username == null || password == null) {
            return "redirect:" + request.getContextPath() + "/admin/login.jsp";
        }

        AdminService adminService = new AdminServiceImpl();
        User user = adminService.login(username, password);

        if (user != null) {
            request.getSession().setAttribute("admin", user);
            return "redirect:" + request.getContextPath() + "/admin/admin.jsp";
        } else {
            //
            return "redirect:" + request.getContextPath() + "/admin/login.jsp";
        }

    }
}
